Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

es6-iterator

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

es6-iterator

Iterator abstraction based on ES6 specification

  • 2.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
7.8M
decreased by-4.43%
Maintainers
1
Weekly downloads
 
Created

What is es6-iterator?

The es6-iterator package provides an implementation of the ECMAScript 6 (ES6) iteration protocols. It includes the iterator interface, which allows JavaScript objects to define or customize their iteration behavior. This package is useful for creating custom iterable objects and for using iterators in environments that do not fully support ES6 features.

What are es6-iterator's main functionalities?

Creating custom iterators

This code sample demonstrates how to create a simple iterator that produces a sequence of numbers from 0 to 4. The iterator has a 'next' method that conforms to the iterator protocol.

{"next": function() { return this._current < this._end ? {value: this._current++, done: false} : {done: true}; }, "_current": 0, "_end": 5}

Using for-of loops with custom iterators

This code sample shows how to use a for-of loop with a custom iterator created by the es6-iterator package. The 'createIterator' function would return an iterator over the array [1, 2, 3], and the for-of loop would log each value to the console.

var it = createIterator([1, 2, 3]); for (var value of it) { console.log(value); }

Implementing iterable protocol

This code sample illustrates how to implement the iterable protocol by adding a '[Symbol.iterator]' method that returns the object itself, which must also have a 'next' method to be a valid iterator.

{"[Symbol.iterator]": function() { return this; }, "next": function() { /* ... */ }}

Other packages similar to es6-iterator

Keywords

FAQs

Package last updated on 17 Oct 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc